package com.aggron.controller;


import com.aggron.common.JsonData;
import com.aggron.constants.ControllerConstants;
import com.aggron.params.AclModuleParams;
import com.aggron.service.ISysAclModuleService;
import com.aggron.service.SysTreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuhuan
 * @since 2018-06-02
 */
@RestController
@RequestMapping("/sys/aclModule")
public class SysAclModuleController {
    @Autowired
    private ISysAclModuleService iSysAclModuleService;

    @Autowired
    private SysTreeService sysTreeService;

    @GetMapping("/tree")
    public JsonData aclModule(){
        return JsonData.success(sysTreeService.aclModuleTree());
    }


    @PostMapping("/save")
    public JsonData saveAclModule(@RequestBody AclModuleParams aclModuleParams){
        iSysAclModuleService.save(aclModuleParams);
        return JsonData.success(ControllerConstants.ADD_SUCCESS_MESSAGE);
    }

    @PostMapping("/update")
    public JsonData updateAclModule(@RequestBody AclModuleParams aclModuleParams){
        iSysAclModuleService.update(aclModuleParams);
        return JsonData.success(ControllerConstants.UPDATE_SUCCESS_MESSAGE);
    }

    @PostMapping("/delete")
    public JsonData delete(@RequestBody AclModuleParams aclModuleParams){
        iSysAclModuleService.delete(aclModuleParams.getId());
        return JsonData.success(ControllerConstants.DELETE_SUCCESS_MESSAGE);
    }
}

